package org.streets.workflow.engine.entities;


import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

import org.streets.workflow.engine.IProcessInstance;
import org.streets.workflow.engine.IToken;


/**
 * @author 非也
 *
 */
@Entity
@Table(name="WF_RT_TOKEN")
public class Token implements IToken {
	@Id
    private String id = null;
	@Column(name="token_state")
	public int state = 0; 
	@Column(name="token_value")
    private Integer value = 0;
	@Column
    private String nodeId = null;
	@Column
    public String processId = null;
    @Column(name="step_num")
    private Integer step = 0;
	@Column
    private String fromActivityId = null;

	private transient IProcessInstance currentProcess;
	
	public Token() {
	    
	}

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }
    
    public Integer getValue() {
        return value;
    }

    public void setValue(Integer v) {
        value = v;
    }

    public Boolean isAlive() {
        return state > 0;
    }

    public void setAlive(Boolean alive) {
        state = 0;
    }

    public String getNodeId() {
        return nodeId;
    }

    public void setNodeId(String nodeId) {
        this.nodeId = nodeId;
    }

    public Integer getStepNumber(){
        return this.step;
    }

    public void setStepNumber(Integer i){
        this.step = i;
    }

    public String getFromActivityId() {
        return this.fromActivityId;
    }

    public void setFromActivityId(String s) {
        this.fromActivityId = s;
    }

    public IProcessInstance getProcess() {
        return currentProcess;
    }

    public void setProcess(IProcessInstance processInstance) {
    
        if (currentProcess != null) {
            this.processId = currentProcess.getId();
        } else {
            this.processId = null;
        }
    }
}
